package com.asset.dispoal.dataDetail.service.commom;

import com.asset.dispoal.commom.page.PagingQuery;
import com.asset.dispoal.dataDetail.domain.db.mapper.SysDataDetailMapper;
import com.asset.dispoal.dataDetail.dto.SysDataTypePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

@Component
public class SysDataTypePageCommand implements BaseCommand<SysDataTypePage, Result<PageVO<SysDataTypePage>>> {

    @Autowired
    private SysDataDetailMapper dataDetailMapper;

    public Result<PageVO<SysDataTypePage>> execute(SysDataTypePage pageRequest) {
        int count = dataDetailMapper.countType(pageRequest);
        Page<SysDataTypePage> page = PagingQuery.getPage(count, pageRequest);
        PageVO<SysDataTypePage> pageVo = new PageVO<>();
        pageVo.setTotalSize(count);
        if (page != null) {
            pageVo.setResult(dataDetailMapper.pageType(page));
        }
        return Result.ok(pageVo);
    }
}
